<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Dianhun
 *
 * @author dragon.hu add @2016.3.17
 */
require_once 'BaseChannel.php';

//电魂
class Dianhun implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="0854d8b00742486a8f86e88f5c2084"; //秘钥
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("dianhun", $_REQUEST);
		
		$ordrId = $_REQUEST['ordrId'];  //电魂订单号
		$amount = $_REQUEST['amount'];  //充值金额(分)
		$appId  = $_REQUEST['appId'];  //appid
		$accountId = $_REQUEST['accountId'];  //账号id
		$cpOrderId = $_REQUEST['cpOrderId'];  //cp订单号
		$sign = $_REQUEST['sign'];  //签名
		$memo = $_REQUEST['memo'];  //备注参数
		
		$mysign = "accountId=".$accountId."&amount=".$amount."&appId=".$appId."&cpOrderId=".$cpOrderId."&ordrId=".$ordrId.$paymentKey;
		
		if($sign == md5($mysign))
		{ //验证通过
			 
			//进行发货
			if(false == $orderLog->recordOrder(STATUS_SUCCESS, $amount/100, $cpOrderId, "dianhun", $platform,$ordrId))
			{
				$ret="FAILURE";
				$orderLog->log("dianhun",array("order"=>$cpOrderId,"money"=>$amount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="SUCCESS";
				$orderLog->log("dianhun",array("order"=>$cpOrderId,"money"=>$amount,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			$ret="FAILURE";
			$orderLog->log("dianhun","  order:$cpOrderId  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}